import viz
import time
from VizSoundAction import *

RED = {"num":0, "col":[1, 0, 0], "lightCol":[1.65, 0, 0]}
GREEN = {"num":1, "col":[0, 0.5019607843137255, 0], "lightCol":[0.1, 0.5019607843137255*2.5, 0.1]}
BLUE = {"num":2, "col":[0.1176470588235294, 0.5647058823529412, 1], "lightCol":[0.1176470588235294*1.75, 0.5647058823529412*1.75, 1.75]}
YELLOW = {"num":3, "col":[1, 0.8431372549019608, 0], "lightCol":[1.65, 0.8431372549019608*1.65, 0]}

buttonData = {"red":RED, "green":GREEN, "blue":BLUE, "yellow":YELLOW}

class SimonButton:
	def __init__(self, vizact, game, resource, position, name, vrsimon):
		self.vizact = vizact
		self.game = game
		self.name = name
		
		self.vizObject = vrsimon.add(resource,pos=position)
		self.vizObject.collideMesh()
		self.vizObject.disable(viz.DYNAMICS)
		
	def getNum(self):
		return buttonData[self.name]["num"]
		
	def press(self):
		pressResult = self.game.addAction(buttonData[self.name]["num"])
		if pressResult == 1:
			self.animate()
			return 1
		elif pressResult == 2:
			self.animate()
			return 2
		else:
			self.animate(False)
			return 0

		
	def animate(self, correct=True):
		if correct == True:
			sound = buttonData[self.name]["num"]
		else:
			sound = 4

		sequence = self.vizact.sequence(play3DSound(sound),
					 self.vizact.fadeTo(buttonData[self.name]["lightCol"],time=0), 
					 self.vizact.sizeTo([1,0,1],speed=8),
					 self.vizact.sizeTo([1,1,1],speed=8),
					 self.vizact.fadeTo(buttonData[self.name]["col"],time=0),
					 stop3DSound(sound))
					 
		self.vizObject.addAction(sequence)
		
	def blink(self, speed):
		delaySignal = self.vizact.signal()
		
		sequence = self.vizact.sequence(play3DSound(buttonData[self.name]["num"]),
			 self.vizact.fadeTo(buttonData[self.name]["lightCol"],time=0),
			 self.vizact.waittime(speed),
			 self.vizact.fadeTo(buttonData[self.name]["col"],time=0),
			 stop3DSound(buttonData[self.name]["num"]))
		
		self.vizObject.addAction(self.game.signal.wait)
		self.vizObject.addAction(sequence)
		self.vizObject.addAction(delaySignal.trigger)
	
		self.game.vrsimon.addAction(delaySignal.wait)
		self.game.vrsimon.addAction(self.vizact.waittime(speed))
		self.game.signal = self.vizact.signal()
		self.game.vrsimon.addAction(self.game.signal.trigger)
		